{extend name="base/common"}

{block name="style"}
<style type="text/css">
    .checkmod dt{
        border-bottom-color: #ebebeb;
        background-color: #ECECEC;
    }
    .form-horizontal .checkbox {
        min-height: 35px;
        margin-left: 20px;
    }
    .checkbox input[type=checkbox] {
        position: absolute;
        margin-top: 4px\9;
        margin-left: -15px;
    }
    .hd{height: 35px}
    .dd_title{height: 35px}
    .divsion{padding-left: 30px}
    .check_text{margin-left: 8px}
</style>
{/block}

{block name="page-header"}
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>访问授权</h2>
        <ol class="breadcrumb">
            <li><a href="{:Url('Auth/index')}">Index</a></li>
            <li class="active"><strong>access</strong></li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>
{/block}

{block name="main"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>授权列表</h5>
                    <div class="ibox-tools">
                        <a href="javascript:window.history.go(-1);" class="btn btn-white btn-xs" data-toggle="tooltip" data-placement="top" title="" data-original-title="返回"><i class="fa fa-reply"></i> 返回</a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="tab-pane in">
                        <form action="{:Url('Auth/writeGroup')}" enctype="application/x-www-form-urlencoded" method="POST" class="form-horizontal auth-form">
                            {volist name="node_list" id="node"}
                            <dl class="checkmod">
                                <dt class="hd">
                                    <label class="checkbox check-all"><input class="auth_rules rules_all i-checks check" type="checkbox" name="rules[]" value="<?php echo $main_rules[$node['url']] ?>"><span class="check_text">{$node.title}管理</span></label>
                                </dt>
                                <dd class="bd">
                                    {present name="node['child']"}
                                    {volist name="node['child']" id="child"}
                                    <div class="rule_check">
                                        <div class="dd_title">
                                            <label class="checkbox check_child" {notempty name="child['tip']"} title='{$child.tip}'{/notempty}>
                                            <input class="auth_rules rules_row i-checks ids" type="checkbox" name="rules[]" value="<?php echo $auth_rules[$child['url']] ?>"/><span class="check_text">{$child.title}</span>
                                            </label>
                                        </div>
                                        {notempty name="child['operator']"}
                                        <span class="divsion">&nbsp;</span>
                                        <span class="child_row">
                                            {volist name="child['operator']" id="op"}
                                                <label class="checkbox" {notempty name="op['tip']"} title='{$op.tip}'{/notempty}>
                                                <input class="auth_rules i-checks ids idds" type="checkbox" name="rules[]" value="<?php echo $auth_rules[$op['url']] ?>"/><span class="check_text">{$op.title}</span>
                                            </label>
                                            {/volist}
                                            </span>
                                        {/notempty}
                                    </div>
                                    {/volist}
                                    {/present}
                                </dd>
                            </dl>
                            {/volist}
                            <div class="hr-line-dashed"></div>
                            <input type="hidden" name="id" value="{$this_group.id}" />
                            <button class="btn btn-return btn-white" onclick="javascript:history.back(-1);return false;">返 回</button>
                            <button type="submit" class="btn submit-btn ajax-post btn-primary" target-form="auth-form">确 定</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script type="text/javascript" src="/static/qtip/jquery.qtip.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/qtip/jquery.qtip.min.css" media="all">
<script type="text/javascript" charset="utf-8">
    +function($){
        var rules = [{$this_group.rules}];
        $('.auth_rules').each(function(){
            if( $.inArray( parseInt(this.value,10),rules )>-1 ){
                $(this).prop('checked',true);
            }
            if(this.value==''){
                $(this).closest('span').remove();
            }
        });

        //全选节点
        $(".check-all").on("ifChanged",function(){
            $(this).closest('dl').find('dd').find('input').iCheck("toggle")
            $(this).closest('dl').find('dd').find('.idds').iCheck("toggle")
        });
        $(".check_child").on("ifChanged",function(){
            $(this).closest('.rule_check').find('.child_row').find('input').iCheck("toggle")
        });


        $('.rules_all').on('change',function(){
            $(this).closest('dl').find('dd').find('input').attr('checked',this.checked);
//        $(this).closest('dl').find('dd').find('input').prop('checked',this.checked);
        });
        $('.rules_row').on('change',function(){
            $(this).closest('.rule_check').find('.child_row').find('input').prop('checked',this.checked);
        });

        $('.checkbox').each(function(){
            $(this).qtip({
                content: {
                    text: $(this).attr('title'),
                    title: $(this).text()
                },
                position: {
                    my: 'bottom center',
                    at: 'top center',
                    target: $(this)
                },
                style: {
                    classes: 'qtip-dark',
                    tip: {
                        corner: true,
                        mimic: false,
                        width: 10,
                        height: 10
                    }
                }
            });
        });

        $('select[name=group]').change(function(){
            location.href = this.value;
        });

        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green'
        });
    }(jQuery);
</script>
{/block}